<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update Buildings</title>
</head>

<body>

<h1>UNO Course Scheduler - Buildings Portal</h1>

<?php
//initialize variables used to connect to database
$db = "scheduler";
$user = "root";
$pass = "";

//counting variable
$i = 0;

//connect to database
mysql_connect("localhost", $user, $pass);
@mysql_select_db($db);

//select statement
$query="SELECT * FROM buildings";
$result=mysql_query($query);

//close
mysql_close();

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);

echo '<p>';

//start table
echo "<table border='0'>";
	
	//create table row with column ID's
	echo "<tr>";
		echo "<td><b>Building Name</b></td>";
		echo "<td><b>Abbreviation</b></td>";
		echo "<td></td>";
		echo "<td></td>";
		echo "<td></td>";
	echo "</tr>";

//loop to walk through and print to screen all entries in buildings table
while ($i < $num_rows) 
{
	//store each building name and abbreviation in a scalar
	$building_id=mysql_result($result,$i,"id");
	$building_name=mysql_result($result,$i,"building_name");
	$abbreviation=mysql_result($result,$i,"abbreviation");
	
	//generate table row for each building on each iteration of the loop
	echo "<tr>";
		echo "<td>$building_name</td>";		//building name cell
		echo "<td style='text-align: center'>$abbreviation</td>";		//building abbreviation cell
		echo "<td>";		//cell containing form for edit building link/button
			echo "<form method='get' action='edit.php'>";
				echo "<input type='hidden' name='id' value='$building_id'>";
				echo "<input type='Submit' value='Edit'>";
			echo "</form>";
		echo "</td>";
		
		echo "<td>";		//cell containing form for delete building link/button
			echo "<form method='get' action='delete.php'>";
				echo "<input type='hidden' name='id' value='$building_id'>";
				echo "<input type='Submit' value='Delete'>";
			echo "</form>";
		echo "</td>";
	
		echo "<td>";		//cell containing form for update classrooms link/button
			echo "<form method='get' action='classrooms/'>";
				echo "<input type='hidden' name='id' value='$building_id'>";
				echo "<input type='hidden' name='name' value='$building_name'>";
				echo "<input type='hidden' name='abbrev' value='$abbreviation'>";
				echo "<input type='Submit' value='Update Classrooms'>";
			echo "</form>";
		echo "</td>";
	echo "</tr>";
		
	//increment counting variable
	$i++;
}

//end table tag
echo "</table>";

echo '</p>';

echo '<p>';

//creates link/button for add building
echo "<form method='get' action='add.php'>";
	echo "<input type='hidden' name='id' value='$num_rows'>";
	echo "<input type='Submit' value='Add Building'>";
echo "</form>";

echo '</p>';

?>

<a href="../">&lt;&lt; Back to Main Portal</a><br />

</body>
</html>